/**
 * 
 */
package com.googlecode.xcache4j;

import java.util.Map;
import java.util.concurrent.Callable;

/**
 * @author xy.du
 *
 */
public interface CacheClient {
	
	boolean add(String key,int exp,Object value)throws Exception;
	
	<T> T get(String key) throws Exception;
	
	<T> T get(String key,Callable<? extends T> callable,final boolean loadDB) throws Exception;
	
	/** 
	 * if value not find,add mutx then getCacheOrLoadFromDB
	 * and set the key exper pamater  
	 * @param key
	 * @param exper
	 * @param callable
	 * @param loadDB
	 * @return
	 * @throws Exception
	 */
	<T> T get(String key,int exper,Callable<? extends T> callable,final boolean loadDB) throws Exception;
	
	/***
	 * 
	 * @param key 
	 * @param callable
	 * @param loadDB
	 * @return if value not find,add mutx then getCacheOrLoadFromDB
	 * @throws Exception
	 */
	<T> T getx(String key,Callable<? extends T> callable,final boolean loadDB) throws Exception;
	
	<T> Map<String,T> getMult(String... keys) throws Exception;
	
	/**
	 * get value with hessian serialize
	 * @param key
	 * @param callable
	 * @param loadDB
	 * @return
	 * @throws Exception
	 */
	<T> T hget(String key,Callable<? extends T> callable,final boolean loadDB) throws Exception;
	
	/**
	 * get value with hessian serialize
	 * @param key
	 * @param callable
	 * @param loadDB
	 * @return if value not find,add mutx then getCacheOrLoadFromDB
	 * @throws Exception
	 */
	<T> T hgetx(String key,Callable<? extends T> callable,final boolean loadDB) throws Exception;
	
	<T> Map<String,T> hgetMult(String... keys) throws Exception;
	
	/**
	 * invoke memcache setWithNoReply 
	 * @param key
	 * @param value
	 * @return
	 */
	<T> boolean set(String key,T value);
	
	/**
	 * setWithNoReply
	 * @param key
	 * @param value
	 * @param exper
	 * @return
	 */
	<T> boolean set(String key,T value,int exper);
	
	<T> boolean setWithNoReply(String key,T value);
	
	<T> boolean setWithNoReply(String key,T value,int exper);
	/**
	 * set value with hessian serialize
	 * default exper is 3600 * 24 * 29
	 * @param key
	 * @param value
	 * @return
	 */
	<T> boolean hset(String key,T value);
	
	/**
	 * get value with hessian serialize
	 * @param key
	 * @param value
	 * @param exper
	 * @return
	 */
	<T> boolean hset(String key,T value, int exper);
	
	boolean delete(String key);
}
